<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <meta name="description" content="Draw a rectangle on the globe surface" />
    <meta name="quarkgis-sandcastle-labels" content="Development" />
    <title>QuarkGIS Demo</title>
    <script type="text/javascript" src="../Sandcastle-header.js"></script>
    <script
      type="text/javascript"
      src="../../../Build/QuarkGISUnminified/QuarkGIS.js"
      nomodule
    ></script>
    <script type="module" src="../load-quarkgis-es6.js"></script>
  </head>
  <body
    class="sandcastle-loading"
    data-sandcastle-bucket="bucket-requirejs.html"
  >
    <style>
      @import url(../templates/bucket.css);
    </style>
    <div id="quarkgisContainer" class="fullSize"></div>
    <div id="loadingOverlay"><h1>Loading...</h1></div>
    <div id="toolbar"></div>
    <script id="quarkgis_sandcastle_script">
      function startup(QuarkGIS) {
        "use strict";
        //Sandcastle_Begin
        var viewer = new QuarkGIS.Viewer("quarkgisContainer");
        viewer.extend(QuarkGIS.viewerQuarkGISInspectorMixin);
        var scene = viewer.scene;
        var ellipsoid = scene.globe.ellipsoid;

        var id1 = "1";
        var id2 = "2";
        var id3 = "3";

        var center1 = QuarkGIS.Cartesian3.fromDegrees(-110, 30);
        var offset = QuarkGIS.Cartesian3.multiplyByScalar(
          ellipsoid.geodeticSurfaceNormal(center1),
          100000,
          new QuarkGIS.Cartesian3()
        );
        var dimensions = new QuarkGIS.Cartesian3(400000.0, 300000.0, 500000.0);
        var boxModelMatrix = QuarkGIS.Matrix4.multiplyByTranslation(
          QuarkGIS.Transforms.eastNorthUpToFixedFrame(center1),
          new QuarkGIS.Cartesian3(0.0, 0.0, dimensions.z * 0.5),
          new QuarkGIS.Matrix4()
        );

        var i1 = new QuarkGIS.GeometryInstance({
          id: id1,
          geometry: QuarkGIS.BoxGeometry.fromDimensions({
            vertexFormat: QuarkGIS.PerInstanceColorAppearance.VERTEX_FORMAT,
            dimensions: dimensions,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: boxModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              new QuarkGIS.Color(1.0, 0.0, 0.0, 0.5)
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });

        var o1 = new QuarkGIS.GeometryInstance({
          id: id1,
          geometry: QuarkGIS.BoxOutlineGeometry.fromDimensions({
            dimensions: dimensions,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: boxModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              QuarkGIS.Color.WHITE
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });

        var center2 = QuarkGIS.Cartesian3.fromDegrees(-100, 30);
        offset = QuarkGIS.Cartesian3.multiplyByScalar(
          ellipsoid.geodeticSurfaceNormal(center2),
          100000,
          new QuarkGIS.Cartesian3()
        );
        var length = 400000.0;
        var topRad = 200000.0;
        var bottomRad = 200000.0;
        var cylinderModelMatrix = QuarkGIS.Matrix4.multiplyByTranslation(
          QuarkGIS.Transforms.eastNorthUpToFixedFrame(center2),
          new QuarkGIS.Cartesian3(0.0, 0.0, length * 0.5),
          new QuarkGIS.Matrix4()
        );

        var i2 = new QuarkGIS.GeometryInstance({
          id: id2,
          geometry: new QuarkGIS.CylinderGeometry({
            length: length,
            topRadius: topRad,
            bottomRadius: 200000.0,
            vertexFormat: QuarkGIS.PerInstanceColorAppearance.VERTEX_FORMAT,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: cylinderModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              new QuarkGIS.Color(1.0, 0.0, 0.0, 0.5)
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });

        var o2 = new QuarkGIS.GeometryInstance({
          id: id2,
          geometry: new QuarkGIS.CylinderOutlineGeometry({
            length: length,
            topRadius: topRad,
            bottomRadius: 200000.0,
            numberOfVerticalLines: 16,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: cylinderModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              QuarkGIS.Color.WHITE
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });

        var center3 = QuarkGIS.Cartesian3.fromDegrees(-90, 30);
        offset = QuarkGIS.Cartesian3.multiplyByScalar(
          ellipsoid.geodeticSurfaceNormal(center3),
          100000,
          new QuarkGIS.Cartesian3()
        );
        var radii = new QuarkGIS.Cartesian3(200000.0, 200000.0, 300000.0);
        var ellipsoidModelMatrix = QuarkGIS.Matrix4.multiplyByTranslation(
          QuarkGIS.Transforms.eastNorthUpToFixedFrame(center3),
          new QuarkGIS.Cartesian3(0.0, 0.0, radii.z),
          new QuarkGIS.Matrix4()
        );
        var i3 = new QuarkGIS.GeometryInstance({
          id: id3,
          geometry: new QuarkGIS.EllipsoidGeometry({
            vertexFormat: QuarkGIS.PerInstanceColorAppearance.VERTEX_FORMAT,
            radii: radii,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: ellipsoidModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              new QuarkGIS.Color(1.0, 0.0, 0.0, 0.5)
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });
        var o3 = new QuarkGIS.GeometryInstance({
          id: id3,
          geometry: new QuarkGIS.EllipsoidOutlineGeometry({
            radii: radii,
            stackPartitions: 16,
            slicePartitions: 8,
            offsetAttribute: QuarkGIS.GeometryOffsetAttribute.ALL,
          }),
          modelMatrix: ellipsoidModelMatrix,
          attributes: {
            color: QuarkGIS.ColorGeometryInstanceAttribute.fromColor(
              QuarkGIS.Color.WHITE
            ),
            offset: QuarkGIS.OffsetGeometryInstanceAttribute.fromCartesian3(
              offset
            ),
          },
        });

        var p = scene.primitives.add(
          new QuarkGIS.Primitive({
            geometryInstances: [i1, i2, i3],
            appearance: new QuarkGIS.PerInstanceColorAppearance({
              closed: true,
            }),
            asynchronous: false,
          })
        );
        var o = scene.primitives.add(
          new QuarkGIS.Primitive({
            geometryInstances: [o1, o2, o3],
            appearance: new QuarkGIS.PerInstanceColorAppearance({
              flat: true,
              renderState: {
                lineWidth: Math.min(2.0, scene.maximumAliasedLineWidth),
              },
            }),
            asynchronous: false,
          })
        );

        Sandcastle.addToolbarButton("Move box", function () {
          var attributes = p.getGeometryInstanceAttributes(id1);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center1),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );

          attributes = o.getGeometryInstanceAttributes(id1);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center1),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );
        });

        Sandcastle.addToolbarButton("Move Cylinder", function () {
          var attributes = p.getGeometryInstanceAttributes(id2);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center2),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );

          attributes = o.getGeometryInstanceAttributes(id2);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center2),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );
        });

        Sandcastle.addToolbarButton("Move ellipsoid", function () {
          var attributes = p.getGeometryInstanceAttributes(id3);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center3),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );

          attributes = o.getGeometryInstanceAttributes(id3);
          offset = QuarkGIS.Cartesian3.multiplyByScalar(
            ellipsoid.geodeticSurfaceNormal(center3),
            150000,
            new QuarkGIS.Cartesian3()
          );
          attributes.offset = QuarkGIS.OffsetGeometryInstanceAttribute.toValue(
            offset,
            attributes.offset
          );
        });
        //Sandcastle_End
        Sandcastle.finishedLoading();
      }
      if (typeof QuarkGIS !== "undefined") {
        window.startupCalled = true;
        startup(QuarkGIS);
      }
    </script>
  </body>
</html>
